package com.chat.api.service;

import com.theokanning.openai.completion.CompletionRequest;
import com.theokanning.openai.service.OpenAiService;

import java.net.SocketTimeoutException;

public class testService {
    public static void main(String[] args) {
        String token = "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";//System.getenv("OPENAI_TOKEN");

        OpenAiService service = new OpenAiService(token);
        CompletionRequest completionRequest = CompletionRequest.builder()
                .model("text-davinci-003")
                .prompt("今天天气怎么样？")
                .temperature(0.5)
                .maxTokens(2048)
                .topP(1D)
                .frequencyPenalty(0D)
                .presencePenalty(0D)
                .build();
        try {
            service.createCompletion(completionRequest).getChoices().forEach(System.out::println);
        } catch (Exception e) {
            System.err.println("Socket timeout. Please check your network connection and try again.");
            // 这里你可以添加重试逻辑，或者结束程序等处理
        }

    }

}
